package com.justnow.offer;

import java.util.ArrayList;

/**
 * @author justnow
 * Created on 2020-09-21
 * Description
 */
public class Wuba03 {
    /**
     * 合并数组
     * @param arrayA int整型ArrayList 数组A
     * @param arrayB int整型ArrayList 数组B
     * @return int整型ArrayList
     */
    public ArrayList<Integer> mergerArrays (ArrayList<Integer> arrayA, ArrayList<Integer> arrayB) {
        // write code here
        ArrayList<Integer> res = new ArrayList<>();
        int lengthA = arrayA.size();
        int lengthB = arrayB.size();
        int indexA = 0, indexB = 0;
        while (indexA < lengthA && indexB < lengthB) {
            if (arrayA.get(indexA) < arrayB.get(indexB)) {
                indexA += 1;
            } else if (arrayA.get(indexA) > arrayB.get(indexB)) {
                indexB += 1;
            } else {
                res.add(arrayA.get(indexA));
                indexA += 1;
                indexB += 1;
            }
        }
        return res;
    }
}
